From 9ee1bd77bfc225d638c8df106238f875025b5e8f Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Mon, 7 Aug 2006 15:35:06 +0100 Subject: [PATCH] [XEN] Clean up shutdown handling and ignore opt_noreboot if dom0 shuts down cleanly. The option is intended only to retain information on the local console in case of a crash. Based on a patch from Muli Ben-Yehuda Signed-off-by: Keir Fraser --- xen/arch/ia64/linux-xen/setup.c | 2 +- xen/arch/powerpc/domain.c | 2 +- xen/arch/x86/genapic/es7000plat.c | 1 - xen/arch/x86/shutdown.c | 17 ++------ xen/arch/x86/traps.c | 2 +- xen/arch/x86/x86_32/traps.c | 2 +- xen/arch/x86/x86_64/traps.c | 2 +- xen/common/Makefile | 1 + xen/common/domain.c | 27 +------------ xen/common/keyhandler.c | 2 +- xen/common/shutdown.c | 66 +++++++++++++++++++++++++++++++ xen/drivers/char/console.c | 19 +++++++-- xen/drivers/char/serial.c | 1 - xen/include/xen/reboot.h | 8 ---- xen/include/xen/shutdown.h | 13 ++++++ 15 files changed, 107 insertions(+), 58 deletions(-) create mode 100644 xen/common/shutdown.c delete mode 100644 xen/include/xen/reboot.h create mode 100644 xen/include/xen/shutdown.h diff --git a/xen/arch/ia64/linux-xen/setup.c b/xen/arch/ia64/linux-xen/setup.c index cc8e197063..6d03910fc7 100644 --- a/xen/arch/ia64/linux-xen/setup.c +++ b/xen/arch/ia64/linux-xen/setup.c @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/xen/arch/powerpc/domain.c b/xen/arch/powerpc/domain.c index 8e4041982f..140b7ec8d2 100644 --- a/xen/arch/powerpc/domain.c +++ b/xen/arch/powerpc/domain.c @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/xen/arch/x86/genapic/es7000plat.c b/xen/arch/x86/genapic/es7000plat.c index 1d7d0d5776..56752061c7 100644 --- a/xen/arch/x86/genapic/es7000plat.c +++ b/xen/arch/x86/genapic/es7000plat.c @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include diff --git a/xen/arch/x86/shutdown.c b/xen/arch/x86/shutdown.c index 4f59b2c983..76dbcca5d2 100644 --- a/xen/arch/x86/shutdown.c +++ b/xen/arch/x86/shutdown.c @@ -11,19 +11,16 @@ #include #include #include +#include +#include +#include +#include #include #include #include #include #include #include -#include -#include -#include - -/* opt_noreboot: If true, machine will need manual reset on error. */ -static int opt_noreboot = 0; -boolean_param("noreboot", opt_noreboot); /* reboot_str: comma-separated list of reboot options. */ static char __initdata reboot_str[10] = ""; @@ -204,12 +201,6 @@ void machine_restart(char * __unused) { int i; - if ( opt_noreboot ) - { - printk("Reboot disabled on cmdline: require manual reset\n"); - machine_halt(); - } - watchdog_disable(); console_start_sync(); diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c index 45d73bc511..2ce1f00562 100644 --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/xen/arch/x86/x86_32/traps.c b/xen/arch/x86/x86_32/traps.c index 3c6d81f21d..4e8c4b075d 100644 --- a/xen/arch/x86/x86_32/traps.c +++ b/xen/arch/x86/x86_32/traps.c @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/xen/arch/x86/x86_64/traps.c b/xen/arch/x86/x86_64/traps.c index 6b674a5b53..f0fa99349b 100644 --- a/xen/arch/x86/x86_64/traps.c +++ b/xen/arch/x86/x86_64/traps.c @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/xen/common/Makefile b/xen/common/Makefile index be3179afdc..4cfde1c83b 100644 --- a/xen/common/Makefile +++ b/xen/common/Makefile @@ -16,6 +16,7 @@ obj-y += sched_bvt.o obj-y += sched_credit.o obj-y += sched_sedf.o obj-y += schedule.o +obj-y += shutdown.o obj-y += softirq.o obj-y += string.o obj-y += symbols.o diff --git a/xen/common/domain.c b/xen/common/domain.c index c837a31c69..5908a23399 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -282,36 +283,12 @@ static __init int domain_shutdown_finaliser_init(void) } __initcall(domain_shutdown_finaliser_init); - void domain_shutdown(struct domain *d, u8 reason) { struct vcpu *v; if ( d->domain_id == 0 ) - { - extern void machine_restart(char *); - extern void machine_halt(void); - - debugger_trap_immediate(); - - if ( reason == SHUTDOWN_poweroff ) - { - printk("Domain 0 halted: halting machine.\n"); - machine_halt(); - } - else if ( reason == SHUTDOWN_crash ) - { - printk("Domain 0 crashed: rebooting machine in 5 seconds.\n"); - watchdog_disable(); - mdelay(5000); - machine_restart(0); - } - else - { - printk("Domain 0 shutdown: rebooting machine.\n"); - machine_restart(0); - } - } + dom0_shutdown(reason); /* Mark the domain as shutting down. */ d->shutdown_code = reason; diff --git a/xen/common/keyhandler.c b/xen/common/keyhandler.c index 3f286e3ae6..21e5862a08 100644 --- a/xen/common/keyhandler.c +++ b/xen/common/keyhandler.c @@ -4,7 +4,7 @@ #include #include -#include +#include #include #include #include diff --git a/xen/common/shutdown.c b/xen/common/shutdown.c new file mode 100644 index 0000000000..1baea16205 --- /dev/null +++ b/xen/common/shutdown.c @@ -0,0 +1,66 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* opt_noreboot: If true, machine will need manual reset on error. */ +int opt_noreboot; +boolean_param("noreboot", opt_noreboot); + +static void maybe_reboot(void) +{ + if ( opt_noreboot ) + { + printk("'noreboot' set - not rebooting.\n"); + machine_halt(); + } + else + { + printk("rebooting machine in 5 seconds.\n"); + watchdog_disable(); + mdelay(5000); + machine_restart(NULL); + } +} + +void dom0_shutdown(u8 reason) +{ + debugger_trap_immediate(); + + switch ( reason ) + { + case SHUTDOWN_poweroff: + { + printk("Domain 0 halted: halting machine.\n"); + machine_halt(); + break; /* not reached */ + } + + case SHUTDOWN_crash: + { + printk("Domain 0 crashed: "); + maybe_reboot(); + break; /* not reached */ + } + + case SHUTDOWN_reboot: + { + printk("Domain 0 shutdown: rebooting machine.\n"); + machine_restart(NULL); + break; /* not reached */ + } + + default: + { + printk("Domain 0 shutdown (unknown reason %u): ", reason); + maybe_reboot(); + break; /* not reached */ + } + } +} + diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index f5ca219f9c..1e7f107966 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -730,14 +731,24 @@ void panic(const char *fmt, ...) printk("Panic on CPU %d:\n", smp_processor_id()); printk(buf); printk("****************************************\n\n"); - printk("Reboot in five seconds...\n"); + if ( opt_noreboot ) + printk("Manual reset required ('noreboot' specified)\n"); + else + printk("Reboot in five seconds...\n"); spin_unlock_irqrestore(&lock, flags); debugger_trap_immediate(); - watchdog_disable(); - mdelay(5000); - machine_restart(0); + if ( opt_noreboot ) + { + machine_halt(); + } + else + { + watchdog_disable(); + mdelay(5000); + machine_restart(NULL); + } } void __bug(char *file, int line) diff --git a/xen/drivers/char/serial.c b/xen/drivers/char/serial.c index 4ee5237804..93bb556204 100644 --- a/xen/drivers/char/serial.c +++ b/xen/drivers/char/serial.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include diff --git a/xen/include/xen/reboot.h b/xen/include/xen/reboot.h deleted file mode 100644 index 8ef2d96cf8..0000000000 --- a/xen/include/xen/reboot.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef _LINUX_REBOOT_H -#define _LINUX_REBOOT_H - -extern void machine_restart(char *cmd); -extern void machine_halt(void); -extern void machine_power_off(void); - -#endif /* _LINUX_REBOOT_H */ diff --git a/xen/include/xen/shutdown.h b/xen/include/xen/shutdown.h new file mode 100644 index 0000000000..cfe20002d8 --- /dev/null +++ b/xen/include/xen/shutdown.h @@ -0,0 +1,13 @@ +#ifndef __XEN_SHUTDOWN_H__ +#define __XEN_SHUTDOWN_H__ + +/* opt_noreboot: If true, machine will need manual reset on error. */ +extern int opt_noreboot; + +void dom0_shutdown(u8 reason); + +void machine_restart(char *cmd); +void machine_halt(void); +void machine_power_off(void); + +#endif /* __XEN_SHUTDOWN_H__ */ -- 2.30.2